package com.zs4sdk.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.zs4gamesdk.R;
import com.zs4sdk.Zs4GameMenu;
import com.zs4sdk.common.Extra;

import org.w3c.dom.Text;

/**
 * Created by Administrator on 2018/5/9.
 */

public class Zs4GameTipDialog extends Dialog implements View.OnClickListener {
    public Zs4GameTipDialog(@NonNull Context context) {
        super(context, R.style.full_dialog);
        View view = LayoutInflater.from(context).inflate(R.layout.zs4game_dlg_start_game_tip,null);
        setContentView(view);
        initViewWidth();
        TextView tvBack = (TextView)view.findViewById(R.id.tvBack);
        tvBack.setOnClickListener(this);

        TextView tvStartGame =(TextView) view.findViewById(R.id.tvStartGame);
        tvStartGame.setOnClickListener(this);
        if(Extra.isComplex()){
            tvBack.setText(getContext().getResources().getString(R.string.zs4game_user_protocol));
            tvStartGame.setText(getContext().getResources().getString(R.string.zs4game_user_protocol_start));
        }

    }

    private void initViewWidth() {
        View rootLayout = this.findViewById(R.id.dlg_root);
        int windowWidth = this.getContext().getResources().getDisplayMetrics().widthPixels;
        int loginWidth = this.getContext().getResources().getDimensionPixelSize(R.dimen.zs4gamedimens_width_bannerads);
        Log.e("wid", " loginWidth is " + loginWidth + " windowWidth is " + windowWidth);
        if (loginWidth >= windowWidth) {
            loginWidth = windowWidth;
        } else if (loginWidth < windowWidth && loginWidth > windowWidth / 2) {
            // loginWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
        } else {
            loginWidth = windowWidth / 2;
            //  loginWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
        }
        rootLayout.getLayoutParams().width = loginWidth;
    }
            @Override
    public void onClick(View view) {
        int id = view.getId();
        if(id == R.id.tvBack){
            dismiss();
            if(Extra.isComplex()){
                Zs4GameMenu.showWebViewForProtocol(getContext());
            }
        }else if(R.id.tvStartGame == id){
            startGame();
        }
    }

    public void closeDialog(){
        this.dismiss();
    }
    public void startGame(){

    }

    public void showDialog(){
        this.show();
    }
}
